import zhCN from './zh'
import { get, isEmpty } from 'lodash'

export const t = (name, options) => {
  const lang = zhCN
  let content = get(lang, name, null)
  if (!content) {
    console.error(`${lang}: ${name} has no match`)
    return `${lang}.${name}`
  }

  if (!isEmpty(options)) {
    if (options.reason && content.match(/\{.+\}/)) {
      content = content.replace(/\{.+\}/, options.reason)
    }
  }

  return content
}
